/*var sendbindcode = "/member/center/sendbindcode";
var sendcode = "/member/center/sendcode";
var checkMailorMobile = "/member/center/checkMailorMobile";
var editMailorMobile = "/member/center/editMailorMobile";
var bindMailorMobile = "/member/center/bindMailorMobile";
if (typeof window.IS_MOBILE !== "undefined") {
    var sendbindcode = "/mobile/member/center/sendbindcode";
    var sendcode = "/mobile/member/center/sendcode";
    var checkMailorMobile = "/mobile/member/center/checkMailorMobile";
    var editMailorMobile = "/mobile/member/center/editMailorMobile";
    var bindMailorMobile = "/mobile/member/center/bindMailorMobile"
}*/
var wait = 60;
var cce;
$(document).ready(function() {
    $(".get_mail").click(function() {
        var a = $.trim($("#txtEmail").val());
        $.post('/index.php/UserCenter/get_code', {
            type: 1,
            destination: a
        }, function(b) {
            if (b.success) {
                //dialog.alert("消息", "验证码已发至您邮箱中，若找不到请在垃圾邮箱翻翻哦~");
            	$(".get_mail").css("pointer-events","auto");
            	dialog.alert("消息",b.message);
                wait = 60;
                clearTimeout(cce);
                time_2($(".get_mail"));
                $("#get_mail").css("pointer-events","auto");
            } else {
                //dialog.error("消息", "邮件发送错误，请重新发送或联系客服！")
            	dialog.error("消息",c.message);
            }
        },'json')
    });
    $(".get_unbindmail").click(function() {
        var a = "unbind";
        $.get(sendcode, {
            type: 1,
            template: a
        }, function(b) {
            if (b.success) {
                //dialog.alert("消息", "验证码已发至您邮箱中，若找不到请在垃圾邮箱翻翻哦~");
                alert("验证码已发至您邮箱中，若找不到请在垃圾邮箱翻翻哦~");
                wait = 60;
                clearTimeout(cce);
                time_2($(".get_unbindmail"))
            } else {
                //dialog.error("消息", "邮件发送错误，请重新发送或联系客服！")
                alert("邮件发送错误，请重新发送或联系客服！")
            }
        })
    });
    $("#bindmail").click(function() {
        $("#popup-verifyemail").dialog({
            title: "绑定邮箱",
            width: 620
        })
    });
    $("#editmail").click(function() {
        $("#popup-verifyeditemail").dialog({
            title: "修改邮箱",
            width: 620
        })
    });
    $("#editpwd").click(function() {
        $("#popup-verifycontact").dialog({
            title: "修改密码",
            width: 620
        })
    })
    
    
	$(".dropdowncentermenu").css("display", "none");
	$(".dropdowncentermenu2").css("display", "none");
	$("#maintitle").html ("个人中心 - 安全设置"); 
	$(".navbar-absolute-bottom").css ("display" , "none");
	$(".infopanel").css ("display" , "none");
	$(".navbar-brand-center").css ("margin-left" , "0px");
	checkmargin ();
	 $(".settingtab").click(function(){
	  tab = $(this).attr('data-id');
	  //alert(tab);
	  $('.settingtab').removeClass('active');
	  $('.settingContainer').hide();
	  $(this).addClass('active');
	  $("#"+tab).show();
	}); 
    
    
    
});
function time_2(a) {
    if (wait == 0) {
        a.removeAttr("disabled");
        a.val("点击获取");
        wait = 60;
        $("#get_mail").css("pointer-events","auto");
    } else {
        a.attr("disabled", "disabled");
        a.val("(" + wait + ")秒后重新获取验证码");
        wait--;
        cce = setTimeout(function() {
            time_2(a)
        }, 1000)
    }
}
function checkUserMail() {
    var b = $.trim($("#txtEmail").val());
    var a = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
    if (b == "") {
        dialog.error("消息", "用户邮箱不能为空！");
        //alert("用户邮箱不能为空！");
        return false
    }
    if (!a.test(b)) {
        dialog.error("消息", "邮箱格式不对！");
        //alert("邮箱格式不对！");
        return false
    }
    $("#btnCheckMail").attr("disabled", "disabled");
    $("#btnCheckMail").val("提交中，请等待...");
    $.post('/index.php/UserCenter/checkMail', {
        type: 1,
        usermail: b
    }, function(c) {
        if (c.success) {
            dialog.alert("消息", c.message);
            //alert("验证码已发至您邮箱中，若找不到请在垃圾邮箱翻翻哦~");
            $("#mailPage").hide();
            $("#mailCodePage").show();
            $("#btnCheckMail").hide();
            $("#btnCheckMailCode").show();
            $(".step1").removeClass("active");
            $(".step2").addClass("active");
            wait = 60;
            clearTimeout(cce);
            time_2($(".get_mail"))
        } else {
            dialog.alert("消息", c.message);
            //alert(c.message);
            $("#btnCheckMail").removeAttr("disabled");
            $("#btnCheckMail").val("下一步")
        }
    },'json')
}
function bindMail() {
    var a = $.trim($("#txtEmailCode").val());
    if (a == "") {
        dialog.error("消息", "验证码不能为空！");
        //alert("验证码不能为空！");
        return false
    }
    $("#btnCheckMailCode").attr("disabled", "disabled");
    $("#btnCheckMailCode").val("提交中，请等待...");
    $.post('/index.php/UserCenter/bindMail', {
        type: 1,
        code: a,
        usermail: $.trim($("#txtEmail").val())
    }, function(b) {
        if (b.success) {   
          /*  dialog.alert("消息", b.message);
            //alert("验证成功， 绑定邮箱成功！");
            window.location.href = "#/center/index/2/?";
            return*/
            $("#btnCheckMailCode").removeAttr("disabled");
            $("#btnCheckMailCode").val("完成")
           //dialog.alert("消息",b.message,null,'/index.php/member/index#/center/index/1');
            //dialog.alert("消息", "绑定邮箱成功！", null, "/member/center/index")
            //alert("绑定邮箱成功！")
			dialog.alert("消息",b.message);
        	setTimeout(function(){

        		window.location.reload()
        	},3000);
        } else {
            dialog.error("消息", b.message);
            //alert(b.message);
            $("#btnCheckMailCode").removeAttr("disabled");
            $("#btnCheckMailCode").val("下一步")
        }
    },'json')
}
function editEmail() {
    var a = $.trim($("#txtEmailCode").val());
    if (a == "") {
        dialog.error("消息", "验证码不能为空！");
        //alert("验证码不能为空！");
        return false
    }
    $("#btnEditMail").attr("disabled", "disabled");
    $("#btnEditMail").val("提交中，请等待...");
    $.post('/index.php/UserCenter/editMail', {
        type: 1,
        usermail: $.trim($("#txtEmail").val()),
        code: a
    }, function(b) {
        if (b.success) {
            $("#btnCheckMailCode").removeAttr("disabled");
            $("#btnCheckMailCode").val("完成")
        	  //dialog.alert("消息",b.message,null,'#/center/index/1');
                //alert("验证成功， 请修改邮箱！");
			dialog.alert("消息",b.message);
        	setTimeout(function(){

        		window.location.reload()
        	},3000);
        } else {
            dialog.error("消息", b.message);
            //alert(b.message);
            $("#btnCheckMailCode").removeAttr("disabled");
            $("#btnCheckMailCode").val("下一步")
        }
    },'json')
}
function checkEditMail() {
	var b = $.trim($("#txtEmail").val());
	var a = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if (b == "") {
		dialog.error("消息", "用户邮箱不能为空！");
		return false
	}
	if (!a.test(b)) {
		dialog.error("消息", "邮箱格式不对！");
		return false
	}
    $("#btnCheckMailCode").attr("disabled", "disabled");
    $("#btnCheckMailCode").val("提交中，请等待...");
	$.post('/index.php/UserCenter/checkEditMail', {
		type: 1,
		usermail: b
	}, function(c) {
		if (c.success) {
            $("#btnCheckMailCode").removeAttr("disabled");
            $("#btnCheckMailCode").val("下一步");
            dialog.alert("消息", c.message);
            //alert("验证码已发至您邮箱中，若找不到请在垃圾邮箱翻翻哦~");
            $("#mailPage").hide();
            $("#mailCodePage").show();
            $("#btnCheckMail").hide();
            $("#btnCheckMailCode").show();
            $(".step1").removeClass("active");
            $(".step2").addClass("active");
            wait = 60;
            clearTimeout(cce);
            time_2($(".get_mail"))
        } else {
            dialog.error("消息", c.message);
            //alert(c.message);
            $("#btnCheckMailCode").removeAttr("disabled");
            $("#btnCheckMailCode").val("下一步")
        }
    },'json')
}
